#include <cstdint>
#include <iostream>
#include <istream>
#include <set>
#include <vector>

using ll = int64_t;
using std::cin, std::cout;

const ll max_n = 1e5+5, rt{1};

ll n, q, c[max_n], fts[max_n];
std::vector<ll> edges[max_n];

void fd_ft(const ll &ft, const ll &now){
    fts[now] = ft;
    for(const ll &nxt: edges[now]){
        if(nxt==ft)continue;
        fd_ft(now, nxt);
    }
}

int main(){
    std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    cin>>n>>q;
    for(ll i{1};i<=n;i++){
        cin>>c[i];
    }
    for(ll i{1};i<n;i++){
        ll u, v;
        cin>>u>>v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    fd_ft(0, rt);
    for(ll i{1};i<=q;i++){
        ll u, v;
        cin>>u>>v;
        std::set<ll> pts;
        pts.emplace(c[u]);
        while(v!=u){
            pts.emplace(c[v]);
            v=fts[v];
        }
        cout<<pts.size()<<'\n';
    }
}